page.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use client";
  2. import { FC, PropsWithChildren, useState } from "react";
  3. import { useRouter } from "@/i18n";
  4. import { useSearchParams } from "next/navigation";
  5. import HeaderBack from "@/components/HeaderBack";
  6. import GoogleCom from "./component/GoogleCom";
  7. import FromCom from "./component/FromCom";
  8. import DomainFooter from "@/components/DomainFooter";
  9. import './page.scss'
  10. import { getLoginApi, getUserInfoApi } from "@/api/user";
  11. import { useGlobalStore } from '@/stores';
  12. import { Toast } from 'antd-mobile'
  13. import { useTranslations } from "next-intl";
  14. interface Props {}
  15. const Login: FC<PropsWithChildren<Props>> = () => {
  16. const t = useTranslations("LoginPage");
  17. const { setToken, setUserInfo } = useGlobalStore();
  18. const router:any = useRouter()
  19. let searchParams = useSearchParams();
  20. let redirect = searchParams.get('redirect') || ''
  21. const [msgError, setMsgError] = useState('')
  22. const loginRequest = async ({userPhone, pwd}: any) => {
  23. let params = {user_phone: userPhone, pwd}
  24. let res = await getLoginApi(params)
  25. if(res.code == 200) {
  26. setToken(res.data.token)
  27. getUserInfoApi().then(res1 => {
  28. if (res1.code == 200) {
  29. Toast.show({ icon: 'success', content: t("loginSuc"), maskClickable: false })
  30. setUserInfo(res1.data)
  31. setTimeout(() => {
  32. router.replace('/' + redirect)
  33. }, 1000)
  34. }
  35. })
  36. }
  37. setMsgError(res.msg || '')
  38. }
  39. return (
  40. <div className="login-box">
  41. <HeaderBack />
  42. <GoogleCom />
  43. <FromCom callbackFun={loginRequest} msgError={msgError}/>
  44. <DomainFooter />
  45. </div>
  46. );
  47. };
  48. export default Login;